//
//  MHCircleMoreViewModel.m
//  MiaoCircle
//
//  Created by 许正荣 on 2018/10/23.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHCircleMoreViewModel.h"
#import "MLCircleInfoMainPageViewModel.h"
#import "MHSearchCircleModel.h"
#import "MHWebViewModel.h"

@implementation MHCircleMoreViewModel
-(void)initialize
{
    [super initialize];
    self.title = @"更多圈子";
    self.shouldPullDownToRefresh = YES;
    self.shouldRequestRemoteDataOnViewDidLoad = YES;
    self.didSelectCommand  = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
        NSIndexPath *indexPath = input;
        [[NSNotificationCenter defaultCenter] postNotificationName:SEARCH_CANCEL_NOTIFICATION_KEY object:nil];
        MHSearchCircleModel *searchMoment =  self.datas[indexPath.row];
        if (searchMoment.isInCircle) {
            
            [MHMomentHelper redirectToGroupChatWithCircleId:searchMoment.circleId service:self.services groupId:searchMoment.circleCode title:searchMoment.title];
            
//            MLCircleInfoMainPageViewModel *viewModel = [[MLCircleInfoMainPageViewModel alloc] initWithServices:self.services params:@{MHViewModelIDKey:@(searchMoment.circleId)}];
//            [self.services pushViewModel:viewModel animated:YES];
            
            return [RACSignal empty];
        }else
        {
            
            
            //http://zg.miaodongquan.com/get-weixin-code.html?appid=wx97ea250bca340197&scope=snsapi_userinfo&state=&redirect_uri=http%3A%2F%2Fwx.acgame100.com%2Fjoin-circle.html%3FcircleId%3D1232%26userId%3D2017
            //            http://zg.miaodongquan.com/get-weixin-code.html?appid=wx97ea250bca340197&scope=snsapi_userinfo&state=&redirect_uri=http://wx.acgame100.com/join-circle.html?circleId=1232&userId=2017
            
            //            NSString *detailUrl =  @"http://zg.miaodongquan.com/get-weixin-code.html?appid=wx97ea250bca340197&scope=snsapi_userinfo&state=&redirect_uri=http://wx.acgame100.com/join-circle.html?circleId=";
            
            NSString *detailUrl =  [NSString stringWithFormat:@"%@join-circle-app.html?circleId=",[MHConfigureManager h5BaseUrl]];
            NSURL *url = [NSURL URLWithString: [NSString stringWithFormat:@"%@%ld&userId=%d",detailUrl,(long)searchMoment.circleId,[MHHTTPService sharedInstance].currentUser.userId]];
            NSURLRequest *request = [NSURLRequest requestWithURL:url];
            MHWebViewModel * webViewModel = [[MHWebViewModel alloc] initWithServices:self.services params:@{MHViewModelRequestKey:request}];
            webViewModel.showBottomButton = false;
            [self.services pushViewModel:webViewModel animated:YES];
            return [RACSignal empty];
        }
        
        
    }];
    
    
}

-(RACSignal *)customSignalWithPage:(NSInteger)page
{
    return  [self.services.client searchCirclePagedListWithTitle:self.searchText pageNum:page pageSize:self.perPage];
}

@end
